package k1_exercise;

import java.util.Arrays;

public class Array_headTailItemSwap {

    /**
     * 首尾交换 {1,2,5,6,7,9}  ->  {9,7,6,5,2,1}
     */
    public static void main(String[] args) {

        //初始化原数组
        int[] nums = {1,2,5,6,7,9,3};

        int tmp = 0;

        //这里必须只能循环整个数组长度的一半，否则相当于交换两次，结果与原数组一致
        for (int i = 0; i < nums.length/2 ; i++) {
            tmp = nums[i];
            nums[i] = nums[nums.length-1-i];
            nums[nums.length-1-i] = tmp;
        }
        System.out.println(Arrays.toString(nums));
    }
}